package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * PROJECT_NAME: sky-take-out
 * NAME: SetmealController
 * USER: zhang
 * DATE: 2023/5/18
 * DESCRIPTION :B端-套餐信息表现层接口
 */
@RestController
@Slf4j
@Api(tags = "B端-套餐信息表现层接口")
@RequestMapping("/admin/setmeal")
public class SetmealController {
    @Resource
    private SetmealService setmealService;

    /**
     * 添加套餐
     * @param setmealDTO 用于接受套餐和菜品数据的Bean
     * @return 全局通用返回Bean
     */
    @ApiOperation("B端-添加套餐功能")
    @PostMapping
    public Result insertSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.insertSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 条件分页查询
     * @param setmealPageQueryDTO 分页参数Bean
     * @return 分页查的结果
     */
    @ApiOperation("B端-条件分页查询套餐功能")
    @GetMapping("/page")
    public Result<PageResult> selectSetmealByPage(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult pageResult = setmealService.selectSetmealByPage(setmealPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 批量删除套餐
     * @param ids 要删除套餐信息的集合
     * @return 全局通用返回Bean
     */
    @ApiOperation("B端-批量删除套餐功能")
    @DeleteMapping
    public Result deleteSetmeal(@RequestParam List<Long> ids){
        setmealService.deleteSetmeal(ids);
        return Result.success();
    }

    /**
     * 基于id查询套餐信息
     * @param id 要查询的套餐id
     * @return 基于id查询到的套餐信息
     */
    @ApiOperation("B端-基于id查询套餐功能")
    @GetMapping("/{id}")
    public Result<SetmealVO> selectSetmealById(@PathVariable Long id){
        SetmealVO setmealVO = setmealService.selectSetmealById(id);
        return Result.success(setmealVO);
    }

    /**
     * 修改套餐信息
     * @param setmealDTO 要修改的数据
     * @return 全局通用返回Bean
     */
    @ApiOperation("B端-修改套餐功能")
    @PutMapping
    public Result updateSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.updateSetmeal(setmealDTO);
        return Result.success();
    }

    /**
     * 套餐的启售/停售
     * @param status 修改后的状态
     * @param id 要修改菜品的id
     * @return 全局通用返回Bean
     */
    @ApiOperation("B端-套餐起售/停售功能")
    @PostMapping("status/{status}")
    public Result modifyStatus(@PathVariable Integer status,Long id){
        Setmeal setmeal = new Setmeal();
        setmeal.setStatus(status);
        setmeal.setId(id);
        setmealService.modifyStatus(setmeal);
        return Result.success();
    }
}
